#!/bin/bash
# tcp_connection_stress_test.sh

echo "=== TCP连接建立能力测试 ==="

test_tcp_connections() {
    local ip=$1
    local name=$2
    local port=80
    
    echo -e "\n测试 $name 的TCP连接建立能力:"
    
    # 测试建立1000个TCP连接的速度
    start_time=$(date +%s%N)
    
    for i in {1..10000}; do
        (timeout 1 bash -c "echo > /dev/tcp/$ip/$port" 2>/dev/null) &
    done
    
    wait
    end_time=$(date +%s%N)
    
    duration=$(( (end_time - start_time) / 1000000 ))
    echo "建立10000个TCP连接耗时: ${duration}ms"
}

test_tcp_connections "43.135.186.249" "腾讯云"
test_tcp_connections "157.230.165.12" "DigitalOcean"